package com.renjun.smweb.controller.StatisticsController;

import com.alibaba.fastjson.JSONObject;
import com.renjun.smweb.annotation.AuthorityDeclaration;
import com.renjun.smweb.commons.util.ResponseUtils;
import com.renjun.smweb.dao.pojo.LoginInfo;
import com.renjun.smweb.service.StatisticsService.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * Created by RenJun on 2017/3/2.
 * 统计类综合控制器
 */

@Controller
@RequestMapping("/statistics")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 报名登记统计（市级）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/registerStatisticsBySj", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-10", desc = "报名登记统计（市级）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject registerStatisticsBySj(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        // TODO: 2017/3/2

        return rs;
    }

    /**
     * 报名登记统计（区县小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/registerStatisticsByQxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-11", desc = "报名登记统计（区县小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject registerStatisticsByQxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.registerStatisticsByQxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计导出（区县小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expRegisterStatisticsByQxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-12", desc = "报名登记统计导出（区县小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expRegisterStatisticsByQxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expRegisterStatisticsByQxXb(params);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计（区县托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/registerStatisticsByQxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-13", desc = "报名登记统计（区县托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject registerStatisticsByQxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.registerStatisticsByQxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }



    /**
     * 报名登记统计导出（区县托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expRegisterStatisticsByQxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-14", desc = "报名登记统计导出（区县托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expRegisterStatisticsByQxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expRegisterStatisticsByQxTb(params);
        }catch (Exception e){
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计（学校小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/registerStatisticsByXxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-15", desc = "报名登记统计（学校小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject registerStatisticsByXxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.registerStatisticsByXxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计导出（学校小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expRegisterStatisticsByXxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-16", desc = "报名登记统计导出（学校小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expRegisterStatisticsByXxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expRegisterStatisticsByXxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计（学校托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/registerStatisticsByXxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-17", desc = "报名登记统计（学校托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject registerStatisticsByXxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.registerStatisticsByXxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 报名登记统计导出（学校托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expRegisterStatisticsByXxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M6-18", desc = "报名登记统计导出（学校托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expRegisterStatisticsByXxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expRegisterStatisticsByXxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }


    /**
     * 录取统计（市级）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/admissionStatisticsBySj", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-5", desc = "录取统计（市级）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject admissionStatisticsBySj(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> params = ResponseUtils.createRequestParamsMap(request);
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        // TODO: 2017/3/2

        return rs;
    }

    /**
     * 录取统计（区县小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/admissionStatisticsByQxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-6", desc = "录取统计（区县小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject admissionStatisticsByQxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.admissionStatisticsByQxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计导出（区县小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expAdmissionStatisticsByQxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-7", desc = "录取统计导出（区县小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expAdmissionStatisticsByQxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expAdmissionStatisticsByQxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            rs.put("message",e.getMessage());
        }
        return rs;
    }


    /**
     * 录取统计（区县托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/admissionStatisticsByQxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-8", desc = "录取统计（区县托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject admissionStatisticsByQxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.admissionStatisticsByQxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计导出（区县托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expAdmissionStatisticsByQxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-9", desc = "录取统计导出（区县托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expAdmissionStatisticsByQxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expAdmissionStatisticsByQxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计（学校小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/admissionStatisticsByXxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-10", desc = "录取统计（学校小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject admissionStatisticsByXxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.admissionStatisticsByXxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计导出（学校小班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expAdmissionStatisticsByXxXb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-14", desc = "录取统计导出（学校小班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expAdmissionStatisticsByXxXb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expAdmissionStatisticsByXxXb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计（学校托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/admissionStatisticsByXxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-15", desc = "录取统计（学校托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject admissionStatisticsByXxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.admissionStatisticsByXxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

    /**
     * 录取统计导出（学校托班）
     * @param request
     * @return []
     */
    @RequestMapping(value = "/expAdmissionStatisticsByXxTb", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M7-16", desc = "录取统计导出（学校托班）",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject expAdmissionStatisticsByXxTb(HttpServletRequest request, HttpServletResponse response) {
        Map<String,Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.expAdmissionStatisticsByXxTb(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }


    /**
     * 首页各类数据统计
     * @param request
     * @return []
     */
    @RequestMapping(value = "/homeStatistics", method = RequestMethod.POST)
    @ResponseBody
    @AuthorityDeclaration(id = "M8-1", desc = "首页各类数据统计",reqParam = "",resBody = "",errMsgs = "sql异常")
    public JSONObject homeStatistics(HttpServletRequest request, HttpServletResponse response) {
        Map<String, Object> params = ResponseUtils.createRequestAndSessionLoginInfo(request);
        LoginInfo loginInfo = (LoginInfo) params.get("userinfo");
        params.put("districtcode",loginInfo.getDistrictcode());
        params.put("stuinfotablename",loginInfo.getStuinfotablename());
        JSONObject rs = ResponseUtils.createErrorResponseBody(null);
        try {
            rs = statisticsService.homeStatistics(params);
        }catch (Exception e) {
            e.printStackTrace();
            return ResponseUtils.createErrorResponseBody(e.getMessage());
        }
        return rs;
    }

}
